package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

/**
 * 登录天数活动
 */
public class LoginDaysActivityCondition extends BaseActivityCondition {

	public LoginDaysActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.LoginDays.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.LoginDays.getValue(), handle);
	}

	public void initDefaultValue(){

	}

	public boolean isCompleted(GamePlayer player) {
		return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
	}

	@Override
	protected void player_BoardLevelHandle(Object object) {
		int args = (int) object;

		// 刚导的活动当天生效
		if (args == 0) {
			if (getValue().compareTo(BigInteger.ZERO) == 0) {
				args = 1;
			} else {
				return;
			}
		}

		BigInteger dayParam = activityConditionInfo.getParamList().get(2);
		sevenDayActivitySetValue(getValue().add(BigInteger.valueOf(args)), dayParam);
	}
}
